package cn.jdy.anquan.web;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.anquan.entity.CompanySafe;
import cn.jdy.anquan.service.CompanySafeService;
import cn.jdy.common.constant.GlobalConstant;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;

/**
 * @author luzhirui
 * @title 中小企业资料库控制类
 * @date 2015-05-31
 */
@Controller
@RequestMapping("/enterprise")
public class CompanySafeCtrl extends BaseCtrl {

  @Autowired
  private CompanySafeService companySafeService;
  
  /**
   * 中小企业资料库查询
   *
   * @return
   */
  @RequestMapping("/search")
  public ModelAndView search(CompanySafe entity, Integer pageNo, Integer pageSize) {
    ModelAndView mv = new ModelAndView("/enterprise/enterpriseList.jsp");
    try {
      if(pageNo==null) pageNo = 1;
      if(pageSize==null) pageSize = 20;

      entity.setiDisplayStart((pageNo - 1) * pageSize);//查询起始值
      entity.setiDisplayLength(pageSize);//查询条数
      entity.setStatus("1");

      Map<String, Object> map = companySafeService.search(entity);

      mv.addAllObjects(map);
      mv.addObject("pageNo", pageNo);
      mv.addObject("bClassList", confService.queryByType(GlobalConstant.TYPE_BUSINESS, 0L));// 查询企业分类信息
      mv.addObject("entity", entity);
      mv.addObject("size", pageSize);
    } catch(Exception e) {
      BaseLog.e(this.getClass(), "查询中小企业资料库错误", e);
    }
    return mv;
  }
  
  /**
   * 中小企业资料库-- 网站名片
   *
   * @return
   */
  @RequestMapping("/card/{id}")
  public ModelAndView card(@PathVariable Integer id) {
    ModelAndView mv = new ModelAndView("/company/index.jsp");
    try {
      CompanySafe ep = companySafeService.findOne("companyId",id);
      
      mv.addObject("ep", ep);
      if(null !=ep){
        mv.addObject("company", ep.getCompany());
      }
    } catch(Exception e) {
      BaseLog.e(this.getClass(), "中小企业资料库-- 网站名片", e);
    }
    return mv;
  }
  
  /**
   * 中小企业资料库-- 网站安全
   *
   * @return
   */
  @RequestMapping("/safe/{id}")
  public ModelAndView safe(@PathVariable Integer id) {
    ModelAndView mv = new ModelAndView("/company/safestatus.jsp");
    try {
      CompanySafe ep = companySafeService.findOne("companyId",id);
      
      mv.addObject("ep", ep);
      if(null !=ep){
        mv.addObject("company", ep.getCompany());
      }
    } catch(Exception e) {
      BaseLog.e(this.getClass(), "中小企业资料库-- 网站名片", e);
    }
    return mv;
  }

  
  

}
